package org.example.mr.exercise;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @author Heshan On 2021/5/23
 */
public class FileMapper extends Mapper<LongWritable, Text, IntWritable, NullWritable> {
    IntWritable digital = new IntWritable();
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        // 防止文本中有空格的输入
        String word = value.toString().trim();
        // 如果是字符串的排序，会按照字典序，也就是2比13大，所以强转为int类型
        digital.set(Integer.parseInt(word));
        context.write(digital, NullWritable.get());
    }
}
